package com.tongjie.hotelbooking.im.conversation.repository;

import com.tongjie.hotelbooking.im.conversation.entiry.Conversation;
import com.tongjie.hotelbooking.user.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface ConversationRepository extends JpaRepository<Conversation, Long>, JpaSpecificationExecutor<Conversation> {

    @Query("Select conversation " +
            "from Conversation conversation " +
            "left join MemberConversation currentMemberConversation on conversation = currentMemberConversation.conversation " +
            "left join MemberConversation  targetMemberConversation on conversation = targetMemberConversation.conversation " +
            "where currentMemberConversation.memberUser = :currentUser " +
            "and targetMemberConversation.memberUser = :targetUser ")
    Conversation getConversationByUsers(@Param("currentUser") User currentUser, @Param("targetUser") User targetUser);

}
